package com.fronald.getbot.misc;

import com.fronald.spec.Conventions;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.fronald.libjutil.FileUtil;

/**
 *
 * @author fronald
 */
public class PluginsInstanciados {

	private static PluginsInstanciados plgs = null;

	private List<Class> plugins = new ArrayList<Class>();

	private Map<String, Class> pluginsByName = new HashMap<String, Class>();

	public static PluginsInstanciados getInstance() throws ClassNotFoundException {
		if (plgs == null) {
			plgs = new PluginsInstanciados();
		}
		return plgs;
	}

	public PluginsInstanciados() throws ClassNotFoundException {
		this.initPlugins();
	}

	public List<Class> getPlugins() {
		return this.plugins;
	}

	public Class getPluginClassByName(String name) {
		return this.pluginsByName.get(name);
	}

	private void initPlugins() throws ClassNotFoundException {
		this.plugins = FileUtil.getClassList(Conventions.PLUGINS_PACKAGE);
		for (Class c : this.plugins) {
			this.pluginsByName.put(c.getName(), c);
		}
	}

}
